from django.contrib import admin
from .models import Question, Choice, Blank, QuestionGroup, UserExerciseLog


class ChoiceInline(admin.StackedInline):
    model = Choice
    extra = 1


class BlankInline(admin.StackedInline):
    model = Blank
    extra = 1


class QuestionAdmin(admin.ModelAdmin):
    inlines = [ChoiceInline, BlankInline]
    list_display = ('id', 'label')


class QuestionGroupAdmin(admin.ModelAdmin):
    filter_horizontal = ('questions',)  # 以横向复选框形式展示多对多关系的问题
    list_display = ('creator', 'name')


class ExerciseLogAdmin(admin.ModelAdmin):
    list_display = ('submit_user', 'submit_time', 'submit_question', 'is_correct')


admin.site.register(Question, QuestionAdmin)
admin.site.register(QuestionGroup, QuestionGroupAdmin)
admin.site.register(UserExerciseLog, ExerciseLogAdmin)
